using System.Windows.Forms;

namespace WinForms窗体练习
{
    public partial class Form1 : Form
    {
        private int Id;//私有的 只能在当前页面计算
        private string Name;

        private List<string> NameList = new List<string>()
        {
            "冯康",
            "张竞文",
            "王燕冰",
            "高琪雅",
            "赵玲蓉",
            "王梦凡",
            "闫泽",
            "牛豪杰"
        };
        private List<string> ImgList = new List<string>()
        {
            "白敬亭.jpg",
            "成熟娃娃.jpeg",
            "大图.jpeg",
            "耳朵图图.jpeg",
            "冯康.jpg",
            "美女.jpeg",
            "娃娃.png",
            "章若楠.png"
        };
        public Form1()
        {
            InitializeComponent();
        }

        public Form1(int Id, string name)
        {
            InitializeComponent();
            this.Id = Id;
            Name = name;
        }

        /// <summary>
        /// 停止
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void btnStop_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            btnStart.Enabled = true;   // 停止后启用启动按钮
            btnStop.Enabled = false;   // 停止后禁用停止按钮
        }
        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            timer1.Start();
            btnStart.Enabled = false;  // 启动后禁用启动按钮
            btnStop.Enabled = true;    // 启动后启用停止按钮
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {

            //在namelist集合中，随机抽取幸运观众
            Random random = new Random();//创建一个随机对象
            var imgindex = random.Next(0, ImgList.Count);
            pictureBox1.Image = Image.FromFile($"Images/{ImgList[imgindex]}");
            var valurindex = random.Next(0, NameList.Count);
            this.LblName.Text = $"恭喜幸运星【{NameList[valurindex]}】中奖！";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void pictureimg_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// from之间传值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Id.ToString(),Name);
        }
    }
}
